-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Lowering Aten op to composite op instead of small ops #8502
base: master
Are you sure you want to change the base?
Conversation
|
||
// Building composite computation. | ||
const std::string name = "composite.gelu"; | ||
const std::string attr = "{approximate = \"none\"}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a dummy str for testing purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a real op attribution for GELU
: https://pytorch.org/docs/stable/generated/torch.nn.GELU.html#torch.nn.GELU
The available value of approximate
is none
or tanh
. The lowering process checks this attribution and decides the sub lower function here. As my changes are in the sub lower function, I manually set this attribution.
It's a common process for composite op which has attributions (defined as non-tensor inputs for composite op, e.g. dim
for Softmax
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I can get the attribution from XlaOp instead of manually setting strings, I will try.
torch_xla/csrc/ops/ops.cpp
Outdated
// Building call to computation. | ||
std::vector<xla::XlaOp> inputs{xla_input}; | ||
xla::XlaOp output = xla::CompositeCall(loctx->builder(), computation, inputs, name, | ||
attr, /*version=*/1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto for version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is for testing, I learned this setting from this XLA UT. I can remove it if it makes no scense.
Hi @Zantares, thanks for the PR! As long as the normal compilation/execution flow is not affected, I think this actually makes the HLO/StableHLO cleaner. Not sure if you have access to TPU to see if the code example in the PR description would run on TPU as well. I applied TPU CI tag, could you please push again to see if TPU CI pass? |
cc @GleasonK in case you know if the composite HLO op affects complication flow |
Thanks! I will fix the format error and push it again to trigger TPU CI. |
This PR is to solve the 2nd question in this issue: supports composite op in training.
Motivation
Composite op is beneficial for performance optimization and we aim to apply it to training too. . According to the response in the issue, the community has no plan to extend this to training currently... Thus, I created this draft PR to demonstrate our intention.
Detail
This PR alters the Aten op lowering process when there isn't a 1:1 mapping to XLA op. It uses composite call instead of small XLA ops. Later, in the optimization process, the composite call can be easily replaced with a custom kernel or decomposed.
This is still a draft PR and only
Gelu
is implemented as an example. If it gets accepted, here are some further suggestions:XLA_COMPOSITE_OP
) to enable this feature. Also, add an op list setting to define which ops can be composed.Example
With this PR, the generated StableHLO is: